﻿using AutoMapper;
using MediatR;
using ProcurementManagement.Applcation.Command.VendorCommand;
using ProcurementManagement.Infrstructre.Interface;

namespace ProcurementManagement.Applcation.CommandHanlers.VendorCommandHanlers
{
    public class VendorUpdCommandHandlers : IRequestHandler<VendorUpdCommand, int>
    {
        protected readonly InterfaceVendorRepository repository;
        protected readonly IMapper mapper;
        public VendorUpdCommandHandlers(InterfaceVendorRepository repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }
        public async Task<int> Handle(VendorUpdCommand request, CancellationToken cancellationToken)
        {
            var list = (await repository.GetAll()).Where(x => x.VendorId == request.UpdDtos.VendorId).First();
            list.VNumber=request.UpdDtos.VNumber;
            list.VName=request.UpdDtos.VName;
            list.VendorTypeId = request.UpdDtos.VendorTypeId;
            list.VGrade = request.UpdDtos.VGrade;
            list.ProvinceId = request.UpdDtos.ProvinceId;
            list.CityId = request.UpdDtos.CityId;
            list.VIndustry = request.UpdDtos.VIndustry;
            list.VContact = request.UpdDtos.VContact;
            list.VDepartment = request.UpdDtos.VDepartment;
            list.VDuty = request.UpdDtos.VDuty;
            list.BPhone = request.UpdDtos.BPhone;
            list.VPhone = request.UpdDtos.VPhone;
            list.VCorp = request.UpdDtos.VCorp;
            list.VFirmAddress = request.UpdDtos.VFirmAddress;
            list.UpdName=request.UpdDtos.UpdName;
            list.UpdTime=request.UpdDtos.UpdTime;
            return await repository.UpdataAsync(list);
        }
    }
}
